// pages/classify/detail/index.js

const APP = getApp()

const SDKVersion = wx.getSystemInfoSync().SDKVersion || '1.0.0'
const [MAJOR, MINOR, PATCH] = SDKVersion.split('.').map(Number)

const canIUse = apiName => {
  if (apiName === 'showModal.cancel') {
    return MAJOR >= 1 && MINOR >= 1
  }
  return true
}

var imageUtil=require('../../../utils/util.js');
Page({
  data:{
    id:0,
    images_src:'',
    modalHidden:true,
    text:''
  },
  onLoad:function(options){
    wx.showToast({
             title: '加载中',
             icon: 'loading',
             duration: 2000
       })
    this.setData({
      id:options.id,
      images_src:decodeURIComponent(options.src),
      product_type:options.product
    })
  },
   imageLoad:function(e){
    var iamge =imageUtil.imagesSuo(e,600,800)
    this.setData({  
      imagewidth: iamge.imageWidth,  
      imageheight: iamge.imageHeight  
    })  
  },
  //加入购物车
  addShop:function(e){
    var product_type=e.target.dataset.product
    var id=e.target.dataset.id
    var that=this
    if(product_type == '2'){
       var decorate=wx.getStorageSync('decorate')
        if(decorate != ''){
            var deArray=decorate+','+id
        }else{
          var deArray=id
        } 
       wx.setStorageSync('decorate', deArray)
       wx.showModal({
          title: '温馨提示',
          content: '是否还需选择装饰图?',
          success: function(res) {
            if (res.confirm) {
               wx.navigateBack({
                  delta: 1, // 回退前 delta(默认为1) 页面
                })
            } else {
              if(wx.getStorageSync('product')==''){
                  that.setData({
                    modalHidden:false,
                    text:'是否需要选择背景图'
                  })
              }else{
                //跳转至上传照片
                wx.navigateTo({
                  url: '../upload/index',
                })
              }
            }
          }
        })
    }
    if(product_type=='1'){
      wx.setStorageSync('product', id)
      if(wx.getStorageSync('decorate')==''){
          this.setData({
            modalHidden:false,
            text:'是否需要选择装饰'
          })
      }else{
         //跳转至上传照片
        wx.navigateTo({
          url: '../upload/index',
        })
      }
    }
  },
  //点击取消
  modalBindcancel:function(){
    this.setData({
       modalHidden:!this.data.modalHidden,
    })
    //跳转至上传照片
    wx.navigateTo({
      url: '../upload/index',
    })
  },
  //点击确定
  modalBindaconfirm:function(){
    this.setData({
       modalHidden:!this.data.modalHidden,
    })
    //跳转至选择产品页
    wx.navigateBack({
      delta: 1, // 回退前 delta(默认为1) 页面
    })
  }

  //
})